package com.io;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by jhoncy on 2016/11/29 0029.
 */
public class FileTest {

    public static void main(String[] args) {
        try {
            Constructor<File> constructor = File.class.getDeclaredConstructor(String.class);
            //获得File类的Constructor对象
            System.out.println("Create File Object with reflection.");
            //使用反射创建File对象
            File file = constructor.newInstance("C:\\MyFile.txt");
            System.out.println("Use File Object to create MyFile.txt on c.");
            //创建新的文件
            file.createNewFile();
            System.out.println("File is created ?" + file.exists());

        } catch (Exception  e) {
            e.printStackTrace();
        }
    }
}
